//
//  JCMyPageCollectionViewController.m
//  ABookOfCartoon
//
//  Created by 于占海 on 15-5-27.
//  Copyright (c) 2015年 Power Of Ants. All rights reserved.
//

#import "JCMyPageCollectionViewController.h"

@interface JCMyPageCollectionViewController ()

@end

@implementation JCMyPageCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;



     self.dbmanager1 = [JCDataCollectManager shareInstance];


     self.Arr = [_dbmanager1 selectInfo];
    NSLog(@"%@",_Arr);

    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"top5"]];

   image.frame = CGRectMake(0, 0, ScreenFramF, ScreenFramS);
    [self.view addSubview:image];

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];


    [_tableView release];


     self.title = @"收藏";

    self.rightButton = self.editButtonItem;
    self.editButtonItem.title = nil;
    _rightButton.title = @"编辑";
    self.navigationItem.rightBarButtonItem = _rightButton;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _Arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    cell.textLabel.text = [_Arr[indexPath.row] BookName];
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    delicateOfCartoonViewController *de = [[delicateOfCartoonViewController alloc] init];
    de.sb = [_Arr[indexPath.row] BookName];
    [self.navigationController pushViewController:de animated:YES];
}


-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    //调用父类的编辑方法
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
    if (!editing) {
        self.navigationItem.rightBarButtonItem.title = @"编辑";
    } else {
        self.navigationItem.rightBarButtonItem.title = @"完成";
    }
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return YES;
}


-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [_Arr removeObjectAtIndex:indexPath.row];
        NSArray *arr = @[indexPath];
        
        [_tableView deleteRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationLeft];
    }
}
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_dbmanager1) {
        [_dbmanager1 deleteInfowithName:[_Arr[indexPath.row] BookName]];
    }
    
    return @"删除";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
